﻿using System;
using System.Collections.Generic;
using System.Linq;
using Helpers;
using TaleWorlds.CampaignSystem.Actions;
using TaleWorlds.CampaignSystem.CharacterDevelopment;
using TaleWorlds.CampaignSystem.Conversation;
using TaleWorlds.CampaignSystem.Extensions;
using TaleWorlds.CampaignSystem.MapEvents;
using TaleWorlds.CampaignSystem.Party;
using TaleWorlds.CampaignSystem.Settlements;
using TaleWorlds.Core;
using TaleWorlds.Library;
using TaleWorlds.Localization;
using TaleWorlds.SaveSystem;

namespace TaleWorlds.CampaignSystem.Issues
{
	// Token: 0x0200030B RID: 779
	public class LadysKnightOutIssueBehavior : CampaignBehaviorBase
	{
		// Token: 0x06002D3B RID: 11579 RVA: 0x000BD504 File Offset: 0x000BB704
		public override void RegisterEvents()
		{
			CampaignEvents.OnCheckForIssueEvent.AddNonSerializedListener(this, new Action<Hero>(this.OnCheckForIssue));
		}

		// Token: 0x06002D3C RID: 11580 RVA: 0x000BD520 File Offset: 0x000BB720
		public void OnCheckForIssue(Hero hero)
		{
			if (this.ConditionsHold(hero))
			{
				Campaign.Current.IssueManager.AddPotentialIssueData(hero, new PotentialIssueData(new PotentialIssueData.StartIssueDelegate(this.OnStartIssue), typeof(LadysKnightOutIssueBehavior.LadysKnightOutIssue), IssueBase.IssueFrequency.Common, null));
				return;
			}
			Campaign.Current.IssueManager.AddPotentialIssueData(hero, new PotentialIssueData(typeof(LadysKnightOutIssueBehavior.LadysKnightOutIssue), IssueBase.IssueFrequency.Common));
		}

		// Token: 0x06002D3D RID: 11581 RVA: 0x000BD584 File Offset: 0x000BB784
		private bool ConditionsHold(Hero issueOwner)
		{
			return issueOwner.IsLord && issueOwner.IsFemale && issueOwner.GetTraitLevel(DefaultTraits.Mercy) < 0 && issueOwner.GetTraitLevel(DefaultTraits.PersonaSoftspoken) <= 0 && issueOwner.GetTraitLevel(DefaultTraits.PersonaCurt) <= 0 && issueOwner.Clan.Leader != issueOwner && issueOwner.Clan != Clan.PlayerClan && issueOwner.IsNoncombatant && issueOwner.CurrentSettlement != null && issueOwner.CurrentSettlement.IsTown && issueOwner.CurrentSettlement.Town.Security <= 50f;
		}

		// Token: 0x06002D3E RID: 11582 RVA: 0x000BD622 File Offset: 0x000BB822
		private IssueBase OnStartIssue(in PotentialIssueData pid, Hero issueOwner)
		{
			return new LadysKnightOutIssueBehavior.LadysKnightOutIssue(issueOwner);
		}

		// Token: 0x06002D3F RID: 11583 RVA: 0x000BD62A File Offset: 0x000BB82A
		public override void SyncData(IDataStore dataStore)
		{
		}

		// Token: 0x04000D8D RID: 3469
		private const IssueBase.IssueFrequency LadysKnightOutIssueFrequency = IssueBase.IssueFrequency.Common;

		// Token: 0x02000633 RID: 1587
		public class LadysKnightOutIssue : IssueBase
		{
			// Token: 0x06004D61 RID: 19809 RVA: 0x00162BCC File Offset: 0x00160DCC
			internal static void AutoGeneratedStaticCollectObjectsLadysKnightOutIssue(object o, List<object> collectedObjects)
			{
				((LadysKnightOutIssueBehavior.LadysKnightOutIssue)o).AutoGeneratedInstanceCollectObjects(collectedObjects);
			}

			// Token: 0x06004D62 RID: 19810 RVA: 0x00162BDA File Offset: 0x00160DDA
			protected override void AutoGeneratedInstanceCollectObjects(List<object> collectedObjects)
			{
				base.AutoGeneratedInstanceCollectObjects(collectedObjects);
			}

			// Token: 0x17000FD9 RID: 4057
			// (get) Token: 0x06004D63 RID: 19811 RVA: 0x00162BE4 File Offset: 0x00160DE4
			public override TextObject IssueBriefByIssueGiver
			{
				get
				{
					TextObject textObject = new TextObject("{=M3af4N66}If you follow tournaments in this region, you'll know that I am a great devotee. I attend as many as I can - I love the spectacle, the tension... Despite this, I've never had a champion fight in my name, which is quite the fashion these days. Would you consider being my champion, {PLAYER.NAME}? I'm sure you could win glory for both of us.[if:convo_merry][ib:confident3]", null);
					StringHelpers.SetCharacterProperties("PLAYER", CharacterObject.PlayerCharacter, textObject, false);
					return textObject;
				}
			}

			// Token: 0x17000FDA RID: 4058
			// (get) Token: 0x06004D64 RID: 19812 RVA: 0x00162C10 File Offset: 0x00160E10
			public override TextObject IssueAcceptByPlayer
			{
				get
				{
					return new TextObject("{=4nbnFMNZ}I can't promise to win, my lady.", null);
				}
			}

			// Token: 0x17000FDB RID: 4059
			// (get) Token: 0x06004D65 RID: 19813 RVA: 0x00162C1D File Offset: 0x00160E1D
			public override TextObject IssueLordSolutionExplanationByIssueGiver
			{
				get
				{
					return new TextObject("{=SzIPvqLk}Of course not. If you don't wish to fight yourself - and I understand you might be quite busy - you could use your influence to convince one of the nobles of this realm to hold their next tournament in my honor.[ib:demure2][if:convo_merry]", null);
				}
			}

			// Token: 0x17000FDC RID: 4060
			// (get) Token: 0x06004D66 RID: 19814 RVA: 0x00162C2A File Offset: 0x00160E2A
			public override TextObject IssuePlayerResponseAfterLordExplanation
			{
				get
				{
					return new TextObject("{=MuwmsOSn}I will consider this. What does it mean to be your champion?", null);
				}
			}

			// Token: 0x17000FDD RID: 4061
			// (get) Token: 0x06004D67 RID: 19815 RVA: 0x00162C38 File Offset: 0x00160E38
			public override TextObject IssueQuestSolutionExplanationByIssueGiver
			{
				get
				{
					TextObject textObject = new TextObject("{=Pnc8ToV1}Just participate in a future tournament in this realm, and say you dedicate your victories to me. {TOURNAMENT_ROUND_GOAL}[ib:hip]", null);
					if (this.TournamentRoundGoal == 5)
					{
						textObject.SetTextVariable("TOURNAMENT_ROUND_GOAL", new TextObject("{=2Rzw16OX}If you can advance to win the tournament, I'm sure that will do us both honor.[ib:hip2][if:convo_relaxed_happy]", null));
					}
					else
					{
						TextObject textObject2 = new TextObject("{=al27CmYV}If you can advance to reach round {ROUND_COUNT}, I'm sure that will do us both honor.[if:convo_calm_friendly][ib:demure]", null);
						textObject2.SetTextVariable("ROUND_COUNT", this.TournamentRoundGoal);
						textObject.SetTextVariable("TOURNAMENT_ROUND_GOAL", textObject2);
					}
					return textObject;
				}
			}

			// Token: 0x17000FDE RID: 4062
			// (get) Token: 0x06004D68 RID: 19816 RVA: 0x00162C9F File Offset: 0x00160E9F
			public override TextObject IssueQuestSolutionAcceptByPlayer
			{
				get
				{
					if (this.TournamentRoundGoal == 5)
					{
						return new TextObject("{=YArbm6TV}Then I will enter the tournament and win it, my lady.", null);
					}
					TextObject textObject = new TextObject("{=w3rcCibp}Then I will enter the tournament and reach round {ROUND_COUNT} my lady.", null);
					textObject.SetTextVariable("ROUND_COUNT", this.TournamentRoundGoal);
					return textObject;
				}
			}

			// Token: 0x17000FDF RID: 4063
			// (get) Token: 0x06004D69 RID: 19817 RVA: 0x00162CD3 File Offset: 0x00160ED3
			public override TextObject IssueLordSolutionAcceptByPlayer
			{
				get
				{
					return new TextObject("{=0WOPfOIH}I'm afraid I don't have time to fight but I can use my influence.", null);
				}
			}

			// Token: 0x17000FE0 RID: 4064
			// (get) Token: 0x06004D6A RID: 19818 RVA: 0x00162CE0 File Offset: 0x00160EE0
			public override TextObject IssueLordSolutionResponseByIssueGiver
			{
				get
				{
					TextObject textObject = new TextObject("{=ZZ7Q3VOG}Thank you my {?PLAYER.GENDER}lady{?}lord{\\?}. I am indeed honored.", null);
					StringHelpers.SetCharacterProperties("PLAYER", base.IssueOwner.CharacterObject, textObject, false);
					return textObject;
				}
			}

			// Token: 0x17000FE1 RID: 4065
			// (get) Token: 0x06004D6B RID: 19819 RVA: 0x00162D14 File Offset: 0x00160F14
			protected override TextObject LordSolutionStartLog
			{
				get
				{
					TextObject textObject = new TextObject("{=EnhdXpQf}{ISSUE_OWNER.LINK} from {ISSUE_OWNER.FACTION}, has told you about of the tournament at the {ISSUE_OWNER_SETTLEMENT}. She wants you to be her champion. {TOURNAMENT_ROUND_GOAL}", null);
					StringHelpers.SetCharacterProperties("ISSUE_OWNER", base.IssueOwner.CharacterObject, textObject, true);
					textObject.SetTextVariable("ISSUE_OWNER_SETTLEMENT", base.IssueOwner.CurrentSettlement.EncyclopediaLinkWithName);
					if (this.TournamentRoundGoal == 5)
					{
						textObject.SetTextVariable("TOURNAMENT_ROUND_GOAL", new TextObject("{=YbzHpFiu}She expects you to win the tournament.", null));
					}
					else
					{
						TextObject textObject2 = new TextObject("{=5qkTxOJ5}She expects you to reach round {ROUND_COUNT}.", null);
						textObject2.SetTextVariable("ROUND_COUNT", this.TournamentRoundGoal);
						textObject.SetTextVariable("TOURNAMENT_ROUND_GOAL", textObject2);
					}
					return textObject;
				}
			}

			// Token: 0x17000FE2 RID: 4066
			// (get) Token: 0x06004D6C RID: 19820 RVA: 0x00162DB0 File Offset: 0x00160FB0
			protected override TextObject LordSolutionCounterOfferRefuseLog
			{
				get
				{
					TextObject textObject = new TextObject("{=IPg30HIs}You told {ISSUE_OWNER.LINK} that instead of her request, the next tournament held will be held in her honor.", null);
					StringHelpers.SetCharacterProperties("ISSUE_OWNER", base.IssueOwner.CharacterObject, textObject, false);
					return textObject;
				}
			}

			// Token: 0x17000FE3 RID: 4067
			// (get) Token: 0x06004D6D RID: 19821 RVA: 0x00162DE2 File Offset: 0x00160FE2
			public override bool IsThereAlternativeSolution
			{
				get
				{
					return false;
				}
			}

			// Token: 0x17000FE4 RID: 4068
			// (get) Token: 0x06004D6E RID: 19822 RVA: 0x00162DE5 File Offset: 0x00160FE5
			public override bool IsThereLordSolution
			{
				get
				{
					return true;
				}
			}

			// Token: 0x17000FE5 RID: 4069
			// (get) Token: 0x06004D6F RID: 19823 RVA: 0x00162DE8 File Offset: 0x00160FE8
			public override TextObject Title
			{
				get
				{
					return new TextObject("{=a4XGmdd9}Lady's Knight Out", null);
				}
			}

			// Token: 0x17000FE6 RID: 4070
			// (get) Token: 0x06004D70 RID: 19824 RVA: 0x00162DF8 File Offset: 0x00160FF8
			public override TextObject Description
			{
				get
				{
					TextObject textObject = new TextObject("{=oBl6SxeJ}{ISSUE_OWNER.LINK} wants you to participate in a tournament in her name.", null);
					StringHelpers.SetCharacterProperties("ISSUE_OWNER", base.IssueOwner.CharacterObject, textObject, false);
					return textObject;
				}
			}

			// Token: 0x17000FE7 RID: 4071
			// (get) Token: 0x06004D71 RID: 19825 RVA: 0x00162E2C File Offset: 0x0016102C
			private int TournamentRoundGoal
			{
				get
				{
					if (base.IssueDifficultyMultiplier > 0.7f)
					{
						return 5;
					}
					if (0.7f >= base.IssueDifficultyMultiplier && base.IssueDifficultyMultiplier > 0.5f)
					{
						return 4;
					}
					if (0.5f >= base.IssueDifficultyMultiplier && base.IssueDifficultyMultiplier > 0.2f)
					{
						return 3;
					}
					return 2;
				}
			}

			// Token: 0x17000FE8 RID: 4072
			// (get) Token: 0x06004D72 RID: 19826 RVA: 0x00162E81 File Offset: 0x00161081
			public override int NeededInfluenceForLordSolution
			{
				get
				{
					return 15 + MathF.Ceiling(30f * base.IssueDifficultyMultiplier);
				}
			}

			// Token: 0x06004D73 RID: 19827 RVA: 0x00162E97 File Offset: 0x00161097
			public LadysKnightOutIssue(Hero issueOwner) : base(issueOwner, CampaignTime.DaysFromNow(30f))
			{
			}

			// Token: 0x06004D74 RID: 19828 RVA: 0x00162EAA File Offset: 0x001610AA
			protected override float GetIssueEffectAmountInternal(IssueEffect issueEffect)
			{
				if (issueEffect == DefaultIssueEffects.SettlementLoyalty)
				{
					return -0.2f;
				}
				if (issueEffect == DefaultIssueEffects.ClanInfluence)
				{
					return -0.1f;
				}
				return 0f;
			}

			// Token: 0x06004D75 RID: 19829 RVA: 0x00162ECD File Offset: 0x001610CD
			protected override void OnGameLoad()
			{
			}

			// Token: 0x06004D76 RID: 19830 RVA: 0x00162ECF File Offset: 0x001610CF
			protected override void HourlyTick()
			{
			}

			// Token: 0x06004D77 RID: 19831 RVA: 0x00162ED1 File Offset: 0x001610D1
			protected override QuestBase GenerateIssueQuest(string questId)
			{
				return new LadysKnightOutIssueBehavior.LadysKnightOutIssueQuest(questId, base.IssueOwner, CampaignTime.DaysFromNow(30f), base.IssueDifficultyMultiplier, 750);
			}

			// Token: 0x06004D78 RID: 19832 RVA: 0x00162EF4 File Offset: 0x001610F4
			public override IssueBase.IssueFrequency GetFrequency()
			{
				return IssueBase.IssueFrequency.Common;
			}

			// Token: 0x06004D79 RID: 19833 RVA: 0x00162EF8 File Offset: 0x001610F8
			protected override bool CanPlayerTakeQuestConditions(Hero issueGiver, out IssueBase.PreconditionFlags flag, out Hero relationHero, out SkillObject skill)
			{
				skill = null;
				relationHero = null;
				flag = IssueBase.PreconditionFlags.None;
				if (issueGiver.GetRelationWithPlayer() < -10f)
				{
					flag |= IssueBase.PreconditionFlags.Relation;
					relationHero = issueGiver;
				}
				if (FactionManager.IsAtWarAgainstFaction(issueGiver.CurrentSettlement.MapFaction, Hero.MainHero.MapFaction))
				{
					flag |= IssueBase.PreconditionFlags.AtWar;
				}
				return flag == IssueBase.PreconditionFlags.None;
			}

			// Token: 0x06004D7A RID: 19834 RVA: 0x00162F50 File Offset: 0x00161150
			public override bool IssueStayAliveConditions()
			{
				return base.IssueOwner.IsNoncombatant && base.IssueOwner.CurrentSettlement != null && base.IssueOwner.CurrentSettlement.IsTown && base.IssueOwner.CurrentSettlement.Town.Security <= 80f;
			}

			// Token: 0x06004D7B RID: 19835 RVA: 0x00162FAA File Offset: 0x001611AA
			protected override void CompleteIssueWithTimedOutConsequences()
			{
			}

			// Token: 0x06004D7C RID: 19836 RVA: 0x00162FAC File Offset: 0x001611AC
			protected override void LordSolutionConsequenceWithRefuseCounterOffer()
			{
				Clan.PlayerClan.AddRenown(7f, true);
				ChangeRelationAction.ApplyPlayerRelation(base.IssueOwner, 5, true, true);
			}

			// Token: 0x040019FD RID: 6653
			private const int TakingQuestRelationLimit = -10;

			// Token: 0x040019FE RID: 6654
			private const int QuestTimeLimit = 30;

			// Token: 0x040019FF RID: 6655
			private const int IssueDuration = 30;

			// Token: 0x04001A00 RID: 6656
			private const int BaseRewardGold = 750;
		}

		// Token: 0x02000634 RID: 1588
		public class LadysKnightOutIssueQuest : QuestBase
		{
			// Token: 0x06004D7D RID: 19837 RVA: 0x00162FCC File Offset: 0x001611CC
			internal static void AutoGeneratedStaticCollectObjectsLadysKnightOutIssueQuest(object o, List<object> collectedObjects)
			{
				((LadysKnightOutIssueBehavior.LadysKnightOutIssueQuest)o).AutoGeneratedInstanceCollectObjects(collectedObjects);
			}

			// Token: 0x06004D7E RID: 19838 RVA: 0x00162FDA File Offset: 0x001611DA
			protected override void AutoGeneratedInstanceCollectObjects(List<object> collectedObjects)
			{
				base.AutoGeneratedInstanceCollectObjects(collectedObjects);
				collectedObjects.Add(this._tournamentTown);
			}

			// Token: 0x06004D7F RID: 19839 RVA: 0x00162FEF File Offset: 0x001611EF
			internal static object AutoGeneratedGetMemberValue_difficultyMultiplier(object o)
			{
				return ((LadysKnightOutIssueBehavior.LadysKnightOutIssueQuest)o)._difficultyMultiplier;
			}

			// Token: 0x06004D80 RID: 19840 RVA: 0x00163001 File Offset: 0x00161201
			internal static object AutoGeneratedGetMemberValue_tournamentTown(object o)
			{
				return ((LadysKnightOutIssueBehavior.LadysKnightOutIssueQuest)o)._tournamentTown;
			}

			// Token: 0x17000FE9 RID: 4073
			// (get) Token: 0x06004D81 RID: 19841 RVA: 0x00163010 File Offset: 0x00161210
			private int TournamentRoundGoal
			{
				get
				{
					if (this._difficultyMultiplier > 0.7f)
					{
						return 5;
					}
					if (0.7f >= this._difficultyMultiplier && this._difficultyMultiplier > 0.5f)
					{
						return 4;
					}
					if (0.5f >= this._difficultyMultiplier && this._difficultyMultiplier > 0.2f)
					{
						return 3;
					}
					return 2;
				}
			}

			// Token: 0x17000FEA RID: 4074
			// (get) Token: 0x06004D82 RID: 19842 RVA: 0x00163068 File Offset: 0x00161268
			private TextObject QuestStartLog
			{
				get
				{
					TextObject textObject = new TextObject("{=kqgadhCF}{QUEST_GIVER.LINK} from {QUEST_GIVER.FACTION}, has asked you to be her champion in an upcoming tournament. {TOURNAMENT_ROUND_GOAL} \nYou told her that you will honor her name in a tournament.", null);
					StringHelpers.SetCharacterProperties("QUEST_GIVER", base.QuestGiver.CharacterObject, textObject, true);
					textObject.SetTextVariable("QUEST_GIVER_TOWN", base.QuestGiver.CurrentSettlement.EncyclopediaLinkWithName);
					if (this.TournamentRoundGoal == 5)
					{
						textObject.SetTextVariable("TOURNAMENT_ROUND_GOAL", new TextObject("{=r8VcYkUf}She expects you to fight in her name and win the tournament.", null));
					}
					else
					{
						TextObject textObject2 = new TextObject("{=edJtO2ua}She expects you to fight in her name and reach at least {ROUND_COUNT}.", null);
						textObject2.SetTextVariable("ROUND_COUNT", this.TournamentRoundGoal);
						textObject.SetTextVariable("TOURNAMENT_ROUND_GOAL", textObject2);
					}
					return textObject;
				}
			}

			// Token: 0x17000FEB RID: 4075
			// (get) Token: 0x06004D83 RID: 19843 RVA: 0x00163104 File Offset: 0x00161304
			private TextObject PlayerWinsTournamentSuccessLog
			{
				get
				{
					TextObject textObject = new TextObject("{=QAg8DQy6}You received a message from {QUEST_GIVER.LINK}.\n \"Thank you for fighting so valiantly in my name. Please take these {REWARD} denars with our gratitude.\"", null);
					StringHelpers.SetCharacterProperties("QUEST_GIVER", base.QuestGiver.CharacterObject, textObject, false);
					textObject.SetTextVariable("REWARD", this.RewardGold);
					return textObject;
				}
			}

			// Token: 0x17000FEC RID: 4076
			// (get) Token: 0x06004D84 RID: 19844 RVA: 0x00163148 File Offset: 0x00161348
			private TextObject PlayerFailedToReachTournamentLevelLog
			{
				get
				{
					TextObject textObject = new TextObject("{=04ti5hcX}{TOURNAMENT_ROUND_GOAL}{QUEST_GIVER.LINK} will certainly be disappointed.", null);
					StringHelpers.SetCharacterProperties("QUEST_GIVER", base.QuestGiver.CharacterObject, textObject, false);
					if (this.TournamentRoundGoal == 5)
					{
						textObject.SetTextVariable("TOURNAMENT_ROUND_GOAL", new TextObject("{=tDNiLiRM}You have failed to win the tournament. ", null));
					}
					else
					{
						TextObject textObject2 = new TextObject("{=CxKC5gqq}You have failed to reach round {ROUND_COUNT} in the tournament. ", null);
						textObject2.SetTextVariable("ROUND_COUNT", this.TournamentRoundGoal);
						textObject.SetTextVariable("TOURNAMENT_ROUND_GOAL", textObject2);
					}
					return textObject;
				}
			}

			// Token: 0x17000FED RID: 4077
			// (get) Token: 0x06004D85 RID: 19845 RVA: 0x001631C8 File Offset: 0x001613C8
			private TextObject PlayerFailedToJoinTournamentLog
			{
				get
				{
					TextObject textObject = new TextObject("{=D40RPEbz}You have failed to enter a tournament in time. {QUEST_GIVER.LINK} will certainly be disappointed.", null);
					StringHelpers.SetCharacterProperties("QUEST_GIVER", base.QuestGiver.CharacterObject, textObject, false);
					return textObject;
				}
			}

			// Token: 0x17000FEE RID: 4078
			// (get) Token: 0x06004D86 RID: 19846 RVA: 0x001631FC File Offset: 0x001613FC
			private TextObject WarDeclaredOnQuestGiversFactionCancelLog
			{
				get
				{
					TextObject textObject = new TextObject("{=zh3Wf6bu}You are now at war with {QUEST_GIVER.LINK}'s faction. Quest is canceled.", null);
					StringHelpers.SetCharacterProperties("QUEST_GIVER", base.QuestGiver.CharacterObject, textObject, false);
					return textObject;
				}
			}

			// Token: 0x17000FEF RID: 4079
			// (get) Token: 0x06004D87 RID: 19847 RVA: 0x00163230 File Offset: 0x00161430
			private TextObject PlayerDeclaredWarQuestLogText
			{
				get
				{
					TextObject textObject = new TextObject("{=bqeWVVEE}Your actions have started a war with {QUEST_GIVER.LINK}'s faction. {?QUEST_GIVER.GENDER}She{?}He{\\?} cancels your agreement and the quest is a failure.", null);
					StringHelpers.SetCharacterProperties("QUEST_GIVER", base.QuestGiver.CharacterObject, textObject, false);
					return textObject;
				}
			}

			// Token: 0x17000FF0 RID: 4080
			// (get) Token: 0x06004D88 RID: 19848 RVA: 0x00163264 File Offset: 0x00161464
			private TextObject QuestGiverIsDeadCancelLog
			{
				get
				{
					TextObject textObject = new TextObject("{=2Ju7Eduu}{QUEST_GIVER.LINK} has died. Your quest is canceled.", null);
					StringHelpers.SetCharacterProperties("QUEST_GIVER", base.QuestGiver.CharacterObject, textObject, false);
					return textObject;
				}
			}

			// Token: 0x17000FF1 RID: 4081
			// (get) Token: 0x06004D89 RID: 19849 RVA: 0x00163298 File Offset: 0x00161498
			private TextObject QuestGiverLeftSettlementCancelLog
			{
				get
				{
					TextObject textObject = new TextObject("{=1RBxhh4W}{QUEST_GIVER.LINK} is not avaliable for this quest anymore.", null);
					StringHelpers.SetCharacterProperties("QUEST_GIVER", base.QuestGiver.CharacterObject, textObject, false);
					return textObject;
				}
			}

			// Token: 0x17000FF2 RID: 4082
			// (get) Token: 0x06004D8A RID: 19850 RVA: 0x001632CA File Offset: 0x001614CA
			private TextObject MainHeroAttackedLadysClansVillageLog
			{
				get
				{
					TextObject textObject = new TextObject("{=Qft5pfYr}You have been accused of a crime, and {QUEST_GIVER.LINK} has declared that you are no longer her champion.", null);
					textObject.SetCharacterProperties("QUEST_GIVER", base.QuestGiver.CharacterObject, false);
					return textObject;
				}
			}

			// Token: 0x17000FF3 RID: 4083
			// (get) Token: 0x06004D8B RID: 19851 RVA: 0x001632EE File Offset: 0x001614EE
			public override TextObject Title
			{
				get
				{
					return new TextObject("{=a4XGmdd9}Lady's Knight Out", null);
				}
			}

			// Token: 0x17000FF4 RID: 4084
			// (get) Token: 0x06004D8C RID: 19852 RVA: 0x001632FB File Offset: 0x001614FB
			public override bool IsRemainingTimeHidden
			{
				get
				{
					return false;
				}
			}

			// Token: 0x06004D8D RID: 19853 RVA: 0x001632FE File Offset: 0x001614FE
			public LadysKnightOutIssueQuest(string questId, Hero questGiver, CampaignTime duration, float issueDifficultyMultiplier, int rewardGold) : base(questId, questGiver, duration, rewardGold)
			{
				this._difficultyMultiplier = issueDifficultyMultiplier;
				this._tournamentTown = null;
				this.SetDialogs();
				base.InitializeQuestOnCreation();
			}

			// Token: 0x06004D8E RID: 19854 RVA: 0x00163326 File Offset: 0x00161526
			protected override void InitializeQuestOnGameLoad()
			{
				this.SetDialogs();
			}

			// Token: 0x06004D8F RID: 19855 RVA: 0x0016332E File Offset: 0x0016152E
			protected override void HourlyTick()
			{
			}

			// Token: 0x06004D90 RID: 19856 RVA: 0x00163330 File Offset: 0x00161530
			protected override void RegisterEvents()
			{
				CampaignEvents.PlayerStartedTournamentMatch.AddNonSerializedListener(this, new Action<Town>(this.OnPlayerStartedTournamentMatch));
				CampaignEvents.PlayerEliminatedFromTournament.AddNonSerializedListener(this, new Action<int, Town>(this.OnPlayerEliminatedFromTournament));
				CampaignEvents.TournamentFinished.AddNonSerializedListener(this, new Action<CharacterObject, MBReadOnlyList<CharacterObject>, Town, ItemObject>(this.OnTournamentFinished));
				CampaignEvents.WarDeclared.AddNonSerializedListener(this, new Action<IFaction, IFaction, DeclareWarAction.DeclareWarDetail>(this.OnWarDeclared));
				CampaignEvents.OnClanChangedKingdomEvent.AddNonSerializedListener(this, new Action<Clan, Kingdom, Kingdom, ChangeKingdomAction.ChangeKingdomActionDetail, bool>(this.OnClanChangedKingdom));
				CampaignEvents.HeroKilledEvent.AddNonSerializedListener(this, new Action<Hero, Hero, KillCharacterAction.KillCharacterActionDetail, bool>(this.OnHeroKilled));
				CampaignEvents.OnSettlementLeftEvent.AddNonSerializedListener(this, new Action<MobileParty, Settlement>(this.OnSettlementLeft));
				CampaignEvents.MapEventStarted.AddNonSerializedListener(this, new Action<MapEvent, PartyBase, PartyBase>(this.OnMapEventStarted));
			}

			// Token: 0x06004D91 RID: 19857 RVA: 0x001633F8 File Offset: 0x001615F8
			private void OnMapEventStarted(MapEvent mapEvent, PartyBase attackerParty, PartyBase defenderParty)
			{
				if ((mapEvent.IsForcingSupplies || mapEvent.IsForcingVolunteers || mapEvent.IsRaid) && attackerParty == PartyBase.MainParty && mapEvent.MapEventSettlement.IsVillage && mapEvent.MapEventSettlement.OwnerClan == base.QuestGiver.Clan)
				{
					this.CriminalActionPerformedTowardsSettlement();
					return;
				}
				if (QuestHelper.CheckMinorMajorCoercion(this, mapEvent, attackerParty))
				{
					QuestHelper.ApplyGenericMinorMajorCoercionConsequences(this, mapEvent);
				}
			}

			// Token: 0x06004D92 RID: 19858 RVA: 0x00163462 File Offset: 0x00161662
			protected override void OnTimedOut()
			{
				base.OnTimedOut();
				this.PlayerFailedToJoinTournamentInTime();
			}

			// Token: 0x06004D93 RID: 19859 RVA: 0x00163470 File Offset: 0x00161670
			protected override void SetDialogs()
			{
				this.OfferDialogFlow = DialogFlow.CreateDialogFlow("issue_classic_quest_start", 100).NpcLine(new TextObject("{=at0iWxo1}It is exciting to think a warrior of your caliber will be my champion. {TOURNAMENT_ROUND_GOAL}", null), null, null).Condition(new ConversationSentence.OnConditionDelegate(this.QuestAcceptedCondition)).Consequence(new ConversationSentence.OnConsequenceDelegate(this.QuestAcceptedConsequences)).CloseDialog();
				this.DiscussDialogFlow = DialogFlow.CreateDialogFlow("quest_discuss", 100).NpcLine(new TextObject("{=iPcbFoDx}Are you prepared for the tournament? Eating well? Staying healthy?", null), null, null).Condition(() => CharacterObject.OneToOneConversationCharacter == base.QuestGiver.CharacterObject).PlayerLine(new TextObject("{=YOmuyrIt}Do you know if there is a tournament starting soon?", null), null).BeginNpcOptions().NpcOption(new TextObject("{=CeYwClaG}Yes, there is one starting at {NEARBY_TOURNAMENTS_LIST}. I am sure the arena master can explain the rules, if you need to know them.", null), new ConversationSentence.OnConditionDelegate(this.NpcTournamentLocationCondition), null, null).CloseDialog().NpcDefaultOption("{=sUfSCLQx}Sadly, I've heard no news of an upcoming tournament. I am sure one will be held before too long.").CloseDialog().EndNpcOptions().CloseDialog();
			}

			// Token: 0x06004D94 RID: 19860 RVA: 0x00163550 File Offset: 0x00161750
			private bool QuestAcceptedCondition()
			{
				if (this.TournamentRoundGoal == 5)
				{
					MBTextManager.SetTextVariable("TOURNAMENT_ROUND_GOAL", new TextObject("{=nctTI5mv}I have every reason to believe you'll win the tournament.", null), false);
				}
				else
				{
					TextObject textObject = new TextObject("{=3FMvLhWV}I have every reason to believe you'll reach round {ROUND_COUNT}.", null);
					textObject.SetTextVariable("ROUND_COUNT", this.TournamentRoundGoal);
					MBTextManager.SetTextVariable("TOURNAMENT_ROUND_GOAL", textObject, false);
				}
				return CharacterObject.OneToOneConversationCharacter == base.QuestGiver.CharacterObject;
			}

			// Token: 0x06004D95 RID: 19861 RVA: 0x001635BA File Offset: 0x001617BA
			private void QuestAcceptedConsequences()
			{
				base.StartQuest();
				base.AddLog(this.QuestStartLog, false);
			}

			// Token: 0x06004D96 RID: 19862 RVA: 0x001635D0 File Offset: 0x001617D0
			private bool NpcTournamentLocationCondition()
			{
				List<Town> list = (from x in Town.AllTowns
				where Campaign.Current.TournamentManager.GetTournamentGame(x) != null && x != Settlement.CurrentSettlement.Town
				select x).ToList<Town>();
				list = (from x in list
				orderby x.Settlement.Position2D.DistanceSquared(Settlement.CurrentSettlement.Position2D)
				select x).ToList<Town>();
				if (list.Count > 0)
				{
					MBTextManager.SetTextVariable("NEARBY_TOURNAMENTS_LIST", list[0].Name, false);
					return true;
				}
				return false;
			}

			// Token: 0x06004D97 RID: 19863 RVA: 0x0016365A File Offset: 0x0016185A
			private void OnPlayerStartedTournamentMatch(Town town)
			{
				this._tournamentTown = town;
			}

			// Token: 0x06004D98 RID: 19864 RVA: 0x00163663 File Offset: 0x00161863
			private void OnPlayerEliminatedFromTournament(int round, Town settlement)
			{
				if (this.TournamentRoundGoal > round + 1)
				{
					this.PlayerCouldntReachedTournamentRoundGoal();
					return;
				}
				this.PlayerReachedTournamentRoundGoal();
			}

			// Token: 0x06004D99 RID: 19865 RVA: 0x0016367D File Offset: 0x0016187D
			private void OnTournamentFinished(CharacterObject winner, MBReadOnlyList<CharacterObject> participants, Town town, ItemObject prize)
			{
				if (town == this._tournamentTown && winner == CharacterObject.PlayerCharacter)
				{
					this.PlayerReachedTournamentRoundGoal();
				}
			}

			// Token: 0x06004D9A RID: 19866 RVA: 0x00163696 File Offset: 0x00161896
			private void OnClanChangedKingdom(Clan clan, Kingdom oldKingdom, Kingdom newKingdom, ChangeKingdomAction.ChangeKingdomActionDetail detail, bool showNotification = true)
			{
				if (base.QuestGiver.MapFaction.IsAtWarWith(Hero.MainHero.MapFaction))
				{
					base.CompleteQuestWithCancel(this.WarDeclaredOnQuestGiversFactionCancelLog);
				}
			}

			// Token: 0x06004D9B RID: 19867 RVA: 0x001636C0 File Offset: 0x001618C0
			private void OnWarDeclared(IFaction faction1, IFaction faction2, DeclareWarAction.DeclareWarDetail detail)
			{
				QuestHelper.CheckWarDeclarationAndFailOrCancelTheQuest(this, faction1, faction2, detail, this.PlayerDeclaredWarQuestLogText, this.WarDeclaredOnQuestGiversFactionCancelLog, false);
			}

			// Token: 0x06004D9C RID: 19868 RVA: 0x001636D8 File Offset: 0x001618D8
			private void OnHeroKilled(Hero victim, Hero killer, KillCharacterAction.KillCharacterActionDetail detail, bool showNotification)
			{
				if (victim == base.QuestGiver)
				{
					this.QuestGiverIsDead();
				}
			}

			// Token: 0x06004D9D RID: 19869 RVA: 0x001636E9 File Offset: 0x001618E9
			private void OnSettlementLeft(MobileParty party, Settlement settlement)
			{
				if (base.QuestGiver.CurrentSettlement == null)
				{
					this.QuestGiverLeftSettlement();
				}
			}

			// Token: 0x06004D9E RID: 19870 RVA: 0x00163700 File Offset: 0x00161900
			private void PlayerReachedTournamentRoundGoal()
			{
				base.AddLog(this.PlayerWinsTournamentSuccessLog, false);
				Clan.PlayerClan.AddRenown(1f, true);
				GiveGoldAction.ApplyBetweenCharacters(null, Hero.MainHero, this.RewardGold, false);
				ChangeRelationAction.ApplyPlayerRelation(base.QuestGiver, 5, true, true);
				base.CompleteQuestWithSuccess();
			}

			// Token: 0x06004D9F RID: 19871 RVA: 0x00163751 File Offset: 0x00161951
			private void PlayerCouldntReachedTournamentRoundGoal()
			{
				ChangeRelationAction.ApplyPlayerRelation(base.QuestGiver, -5, true, true);
				base.CompleteQuestWithFail(this.PlayerFailedToReachTournamentLevelLog);
			}

			// Token: 0x06004DA0 RID: 19872 RVA: 0x0016376E File Offset: 0x0016196E
			private void PlayerFailedToJoinTournamentInTime()
			{
				base.AddLog(this.PlayerFailedToJoinTournamentLog, false);
				ChangeRelationAction.ApplyPlayerRelation(base.QuestGiver, -5, true, true);
			}

			// Token: 0x06004DA1 RID: 19873 RVA: 0x0016378D File Offset: 0x0016198D
			private void QuestGiverIsDead()
			{
				base.CompleteQuestWithCancel(this.QuestGiverIsDeadCancelLog);
			}

			// Token: 0x06004DA2 RID: 19874 RVA: 0x0016379B File Offset: 0x0016199B
			private void QuestGiverLeftSettlement()
			{
				base.CompleteQuestWithCancel(this.QuestGiverLeftSettlementCancelLog);
			}

			// Token: 0x06004DA3 RID: 19875 RVA: 0x001637AC File Offset: 0x001619AC
			private void CriminalActionPerformedTowardsSettlement()
			{
				this.RelationshipChangeWithQuestGiver = -5;
				Tuple<TraitObject, int>[] effectedTraits = new Tuple<TraitObject, int>[]
				{
					new Tuple<TraitObject, int>(DefaultTraits.Honor, -50)
				};
				TraitLevelingHelper.OnIssueSolvedThroughQuest(Hero.MainHero, effectedTraits);
				base.CompleteQuestWithFail(this.MainHeroAttackedLadysClansVillageLog);
			}

			// Token: 0x04001A01 RID: 6657
			[SaveableField(1)]
			private readonly float _difficultyMultiplier;

			// Token: 0x04001A02 RID: 6658
			[SaveableField(2)]
			private Town _tournamentTown;
		}

		// Token: 0x02000635 RID: 1589
		public class LadysKnightOutIssueTypeDefiner : SaveableTypeDefiner
		{
			// Token: 0x06004DA5 RID: 19877 RVA: 0x00163802 File Offset: 0x00161A02
			public LadysKnightOutIssueTypeDefiner() : base(585700)
			{
			}

			// Token: 0x06004DA6 RID: 19878 RVA: 0x0016380F File Offset: 0x00161A0F
			protected override void DefineClassTypes()
			{
				base.AddClassDefinition(typeof(LadysKnightOutIssueBehavior.LadysKnightOutIssue), 1, null);
				base.AddClassDefinition(typeof(LadysKnightOutIssueBehavior.LadysKnightOutIssueQuest), 2, null);
			}
		}
	}
}
